package com.study.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mysql.cj.util.StringUtils;
import com.study.model.Book;
import com.study.service.IBookService;
import com.study.storage.BookDao;
import org.apache.logging.log4j.util.Strings;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @desc:
 * @author: panxiyi
 * @date: 2023/4/12 1:03 下午
 */

@Service
public class BookServiceImpl3 extends ServiceImpl<BookDao, Book> implements IBookService {

    @Autowired
    private BookDao bookDao;

    @Override
    public Boolean delete(Integer id) {
        return bookDao.deleteById(id) > 0;
    }

    @Override
    public IPage<Book> getByPage(Integer currentPage, Integer pageSize, String type, String name, String description) {
        Page page = new Page(currentPage, pageSize);
        LambdaQueryWrapper<Book> lqw = new LambdaQueryWrapper<>();
        lqw.like(!StringUtils.isNullOrEmpty(type), Book::getType, type);
        lqw.like(!StringUtils.isNullOrEmpty(name), Book::getName, name);
        lqw.like(!Strings.isNotBlank(description), Book::getDescription, description);

        page = bookDao.selectPage(page, lqw);
        return page;
    }
}
